package com.demo.common.base.controller;

import com.demo.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.UnauthenticatedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Controller公共组件
 */
public abstract class BaseController {
    protected Logger log = LoggerFactory.getLogger(getClass());

    protected SysUserEntity getUser() {
        if (!SecurityUtils.getSubject().isAuthenticated()) {
            throw new UnauthenticatedException("需要登录");
        }
        return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
    }

    protected Long getUserId() {
        return getUser().getId();
    }
}
